#ifndef SLKCON_H
#define SLKCON_H

#include "Common.h"

class SlkCon
{
	public:
		SlkCon();
		SlkCon(char *path) {loadSlkFile(path);}
		virtual ~SlkCon();
		int loadSlkFile(const char *path);
		int saveSlkFile(const char *path);
		string getData(int x,int y) {return dataTable[getIndex(x,y)];}
		void setData(int x,int y,string data) {dataTable[getIndex(x,y)]=data;}
		bool getStrFlag(int x,int y) {return strFlags[getIndex(x,y)];}
		void setStrFlag(int x,int y,bool sf) {strFlags[getIndex(x,y)]=sf;}
		bool getNullFlag(int attIndex) { return nullFlags[attIndex-1]; }
		int getTableX() { return tableX; }
		int getTableY() { return tableY; }
		int indexByObj(string obj){
			if ( objMap.count(obj)==0 ) return 0;
			return objMap[obj];
		}
		int indexByAtt(string att){
			if ( attMap.count(att)==0 ) return 0;
			return attMap[att];
		}

		bool insertObject(vector<string> &intData,vector<bool> &strsign);

	protected:
		string header;
		int tableX;
		int tableY;
		map<string,int> objMap;
		map<string,int> attMap;
		vector<string> dataTable;
		vector<bool> strFlags;
		vector<bool> nullFlags;

		bool delQuot(string &str);
		void addQuot(string &str);
		void splitStr(string str,int &x,int &y,string &k);

		void makeIndexs();

		int getIndex(int x,int y) { return (x-1)+(y-1)*tableX; }

	private:
};

#endif // SLKCON_H
